<?php
if (!defined("IN_OP"))
{
    exit("You can't access this file directly...");
}
require_once( "class_3d/CheckMode_3d.php" );
$gametype = intval(getvar("gametype"));
$chkGametype = chkGametype($gametype);
$chk = new CheckMode_3d($curruser['acl'], 1, $gametype);
$chk->checkShow3dPage();
$g_betname_3or5 = judge_type($gametype, true);
unset($chk);
$tbl = $g_gametype_3d[$gametype]['en'];
$tblName = $g_gametype_3d[$gametype]['ch'];
$ui = new UI_3D(true);
$tpl = new Template2();
$conf = new Config();
include_once( "class/function_3d.php" );
if ($chkGametype == 3)
{
    include_once( "class_5h/RateConfig_5h.php" );
    $RateConfig_3d = new RateConfig_5h($gametype);
    if ($gametype == 20)
    {
        $numGroup = array(9, 10, 11, 12, 13, 14);
        $_5hFlag = true;
        $_8hFlag = false;
    }
    else
    {
        $numGroup = array(10, 11, 12, 13, 14, 15, 16, 17);
        $_5hFlag = false;
        $_8hFlag = true;
    }
}
else
{
    include_once( "class_3d/RateConfig_3d.php" );
    $RateConfig_3d = new RateConfig_3d($gametype);
    $_5hFlag = false;
    $_8hFlag = false;
    $numGroup = array();
}
$num = getvar("num");
$bettype = getvar("bettype");
$subid = intval(getvar("subid"));
$page = getvar("page");
$page = $page == "" ? 1 : intval($page);
$showType = getvar("showType");
$lid = getvar("lid");
$lid = $lid == "" ? "" : intval($lid);
$dateS = getvar("dates");
$dateE = getvar("datee");
$postTime = $conf->get("paper_post_bet");
$today = date("Hi") <= $postTime ? date("Y-m-d", strtotime("-1 day")) : date("Y-m-d");
if ($dateS == "" || $dateE == "" || !is_date($dateS) || !is_date($dateE))
{
    $dateS = $today;
    $dateE = $today;
}
if ($dateS == $dateE && $dateE == $today)
{
    $x = "";
}
else
{
    $x = "x";
}
if ($num != "all" && !$RateConfig_3d->checkBetNumber($bettype, $num))
{
    if (in_array($bettype, $numGroup))
    {
        $numGroupArr = explode(",", $num);
        $numGroupArrNum = count($numGroupArr);
        if ($numGroupArrNum != count(array_unique($numGroupArr)))
        {
            $ui->showErrorPage("错误的内容-1");
            exit();
        }
        if ($numGroupArrNum != count(array_intersect($RateConfig_3d->getBetTypeNumber($bettype), $numGroupArr)))
        {
            $ui->showErrorPage("错误的内容-2");
            exit();
        }
    }
    else
    {
        $ui->showErrorPage("错误的内容-3");
        exit();
    }
}
if ($bettype != "" && !isset($g_betname_3or5[$bettype . "_" . $subid]))
{
    $ui->showErrorPage("错误的值");
    exit();
}
$timeStart = strtotime($dateS . " 00:00:00");
$timeEnd = strtotime($dateE . " 23:59:59");
$showtitle = "{$tblName} 公司走飞清单";
$betRType = intval(getvar("betRType"));
switch ($betRType)
{
    case 1 :
        $rameSQLStr8 = " and a.rame = 9 AND (a.r5 - (a.back / 100 * a.amount)) <= 0 ";
        $rameTitleStr = " 选项:上缴";
        break;
    case 2 :
        $rameSQLStr8 = " and a.rame = 9 AND (a.r5 - (a.back / 100 * a.amount)) > 0 ";
        $rameTitleStr = " 选项:得分";
        break;
    default :
        $rameSQLStr8 = "";
        $rameTitleStr = " 选项:全部";
        break;
}
$backType = "";
$sql = "SELECT a.*,c.round, c.open FROM {$x}bet8_{$tbl} a";
$sql .= " LEFT JOIN lotto_{$tbl} c ON (a.lotto_id = c.id)";
if ($lid == "")
{
    $sql .= " WHERE (c.open BETWEEN '{$dateS}' AND '{$dateE}') {$rameSQLStr8}";
}
else
{
    $sql .= " WHERE a.lotto_id = {$lid} {$rameSQLStr8}";
}
$sqlTotal = "SELECT count(a.amount),sum(a.amount), sum(a.back / 100 * a.amount),sum(a.r5) FROM {$x}bet8_{$tbl} a";
$sqlTotal .= " LEFT JOIN lotto_{$tbl} c ON (a.lotto_id = c.id)";
if ($lid == "")
{
    $sqlTotal .= " WHERE (c.open BETWEEN '{$dateS}' AND '{$dateE}') ";
}
else
{
    $sqlTotal .= " WHERE a.lotto_id = {$lid} ";
}
$sqlTotal .= " AND rame IN(0,9) {$rameSQLStr8}";
$xyidStr = "";
if ($bettype !== "")
{
    if ($_5hFlag)
    {
        $xyid = intval(getvar("xyid"));
        if (in_array($bettype, $g_betXYArr[$gametype]) && in_array($xyid, array(1, 2)))
        {
            $xyidStr = " AND a.xyid = {$xyid} ";
        }
        $sql .= " AND a.bettype = {$bettype} AND a.subid = {$subid}" . $xyidStr;
        $sqlTotal .= " AND a.bettype ={$bettype} AND a.subid = {$subid}" . $xyidStr;
    }
    else
    {
        $sql .= " AND a.bettype = {$bettype} AND a.subid = {$subid}";
        $sqlTotal .= " AND a.bettype ={$bettype} AND a.subid = {$subid}";
    }
}
$sqlNum = "";
if ($num != "all" && $num != "")
{
    if ($_5hFlag)
    {
        $numArr = explode(",", $num);
        switch ($bettype)
        {
            case "9" :
                if (count($numArr) != 1)
                {
                    exit("error number");
                }
                $sqlNum = " AND numbers = '{$num}'";
                break;
            case "10" :
                $numArrN = count($numArr);
                if ($numArrN == 1)
                {
                    $sqlNum = " AND numbers LIKE '%{$num}%'";
                }
                else if ($numArrN == 2)
                {
                    $sqlNum = " AND numbers = '{$num}'";
                }
                else
                {
                    exit("error number");
                }
                break;
            case "11" :
            case "12" :
                $numArrN = count($numArr);
                if ($numArrN == 1)
                {
                    $sqlNum = " AND numbers LIKE '%{$num}%'";
                }
                else if ($numArrN == 3)
                {
                    $sqlNum = " AND numbers = '{$num}'";
                }
                else
                {
                    exit("error number");
                }
                break;
            case "13" :
                $numArrN = count($numArr);
                if ($numArrN == 1)
                {
                    $sqlNum = " AND numbers LIKE '%{$num}%'";
                }
                else if ($numArrN == 4)
                {
                    $sqlNum = " AND numbers = '{$num}'";
                }
                else
                {
                    exit("error number");
                }
                break;
            case "14" :
                $numArrN = count($numArr);
                if ($numArrN == 1)
                {
                    $sqlNum = " AND numbers LIKE '%{$num}%'";
                }
                else if ($numArrN == 5)
                {
                    $sqlNum = " AND numbers = '{$num}'";
                }
                else
                {
                    exit("error number");
                }
                break;
            default :
                $sqlNum = " AND numbers='{$num}'";
                break;
        }
    }
    else if ($_8hFlag)
    {
        $numArr = explode(",", $num);
        switch ($bettype)
        {
            case "10" :
            case "11" :
            case "12" :
                $numArrN = count($numArr);
                if ($numArrN == 1)
                {
                    $sqlNum = " AND numbers LIKE '%{$num}%'";
                }
                else if ($numArrN == 2)
                {
                    $sqlNum = " AND numbers = '{$num}'";
                }
                else
                {
                    exit("error number");
                }
                break;
            case "13" :
            case "14" :
            case "15" :
                $numArrN = count($numArr);
                if ($numArrN == 1)
                {
                    $sqlNum = " AND numbers LIKE '%{$num}%'";
                }
                else if ($numArrN == 3)
                {
                    $sqlNum = " AND numbers = '{$num}'";
                }
                else
                {
                    exit("error number");
                }
                break;
            case "16" :
                $numArrN = count($numArr);
                if ($numArrN == 1)
                {
                    $sqlNum = " AND numbers LIKE '%{$num}%'";
                }
                else if ($numArrN == 4)
                {
                    $sqlNum = " AND numbers = '{$num}'";
                }
                else
                {
                    exit("error number");
                }
                break;
            case "17" :
                $numArrN = count($numArr);
                if ($numArrN == 1)
                {
                    $sqlNum = " AND numbers LIKE '%{$num}%'";
                }
                else if ($numArrN == 5)
                {
                    $sqlNum = " AND numbers = '{$num}'";
                }
                else
                {
                    exit("error number");
                }
                break;
            default :
                $sqlNum = " AND numbers='{$num}'";
                break;
        }
    }
    else
    {
        switch ($bettype)
        {
            case "24" :
            case "25" :
            case "26" :
            case "27" :
            case "28" :
            case "30" :
            case "31" :
            case "32" :
            case "33" :
            case "34" :
                $sqlNum = " AND a.numbers LIKE '%" . $num . "%'";
                break;
            case "35" :
                $numArr = $RateConfig_3d->mystr_split($num, 1);
                $sqlNum = " AND a.numbers LIKE '%" . $numArr[0] . "%,%" . $numArr[1] . "%,%" . $numArr[2] . "%'";
                break;
            default :
                $sqlNum = " AND a.numbers='" . $num . "'";
                break;
        }
    }
}
$sql .= $sqlNum;
$sqlTotal .= $sqlNum;
$sql .= " ORDER BY a.id DESC";
$rs = getdb($sql, $page, 20);
$totalrecords = $rs->totalrecords;
$littleNum = 0;
$littleAmount = 0;
$littleBack = 0;
$littleB1 = 0;
$ui->header();
$noteArr = array();
$i = 0;
while ($i < 10)
{
    $noteArr[$i] = $conf->get("port_systemuser_" . $i);
    ++$i;
}
echo title("{$tblName} 下注清单", "<a href=\"javascript:window.print()\">列印</a>&nbsp;|&nbsp;<a href=\"javascript:history.back();\">回上一页</a>&nbsp;|&nbsp;");
echo "<table width=758 border=1 cellpadding=3 cellspacing=0>";
echo "<caption class=\"bgImg_{$gametype}\">{$showtitle}</caption>";
echo "<tr class=\"bgClc_{$gametype}\" align=center><td nowrap>单号 / 时间</td><td nowrap> 期数 / 开奖日期</td><td nowrap>下注内容</td><td nowrap>下注金额</td><td nowrap>赔率</td><td nowrap>退水</td><td nowrap>结果</td><td nowrap>备注</td></tr>";
while (!$rs->eof)
{
    echo "<tr class=\"td2\">";
    echo "<td><font color=\"green\">" . $rs->f['id'] . "</font>&nbsp;&nbsp;" . date("m-d H:i:s", $rs->f['createtime']) . "</td>";
    echo "<td>" . $rs->f['round'] . "期&nbsp;<font color=\"green\">" . $rs->f['open'] . "</font></td>";
    echo "<td>";
    if ($_5hFlag)
    {
        echo "<font class='colorXY'>" . $RateConfig_3d->xyidTitle[$rs->f['xyid']] . "</font>";
    }
    echo "【" . $g_betname_3or5[$rs->f['bettype'] . "_" . $rs->f['subid']] . "】&nbsp;" . nl2br($rs->f['line_nums']) . "</td>";
    if (20000 < $rs->f['amount'])
    {
        $color = "alert2";
    }
    else if (10000 < $rs->f['amount'])
    {
        $color = "alert1";
    }
    else
    {
        $color = "";
    }
    echo "<td align=\"right\" class=\"" . $color . "\">" . $rs->f['amount'] . "</td>";
    echo "<td align=\"right\">" . floatval($rs->f['rate']) . "</td>";
    echo "<td align=\"right\">" . round($rs->f['back'] * $rs->f['amount'] / 100, 2) . "</td>";
    echo "<td align=\"right\">" . say_numbercolor($rs->f['r5'], 3) . "</td>";
    if ($rs->f['rame'] == 1)
    {
        $note = "<font color=red>- 逾时 -</font>";
    }
    else if ($rs->f['rame'] == 2)
    {
        $note = "<font color=red>- 取消 -</font>";
    }
    else if ($rs->f['rame'] == 3)
    {
        $note = "<font color=red>- 异常 -</font>";
    }
    else
    {
        $note = "";
        $littleNum += 1;
        $littleAmount += $rs->f['amount'];
        $littleBack += $rs->f['back'] * $rs->f['amount'] / 100;
        $littleB1 += $rs->f['r5'];
    }
    if ($rs->f['account'] != "" && isset($noteArr[$rs->f['account']]))
    {
        $note .= "&nbsp;" . $noteArr[$rs->f['account']];
    }
    else
    {
        $note .= "&nbsp;" . $rs->f['account'];
    }
    echo "<td>" . $note . "</td>";
    echo "</tr>";
    $rs->movenext();
}
if (1 < $rs->totalpages)
{
    echo "<tr align=\"right\" class=\"td1\"><td colspan=\"3\">小计 " . $littleNum . " 笔</td><td>" . $littleAmount . "</td><td>--</td><td>" . round($littleBack, 2) . "</td><td>" . say_numbercolor($littleB1, 3) . "</td><td>&nbsp;</td></tr>";
}
$totalArr = getdb($sqlTotal);
if (!$totalArr->eof)
{
    echo "<tr align=\"right\" class=\"td3\"><td colspan=\"3\">总计 " . $totalArr->f[0] . " 笔</td><td>" . $totalArr->f[1] . "</td><td>--</td><td>" . round($totalArr->f[2], 2) . "</td><td>" . say_numbercolor($totalArr->f[3], 3) . "</td><td>&nbsp;</td></tr>";
}
else
{
    echo "<tr align=\"center\" class=\"td3\"><td colspan=\"8\">查无资料</td></tr>";
}
echo "<tr><td class=\"bgClc_{$gametype}\" colspan=\"8\">" . $rs->pagelink() . "</td></tr>";
echo "</table>";
echo "<script language=\"JavaScript\">";
echo "$(\"tbody tr[class=td2]\").hover(";
echo "  function() {\$(this).addClass(\"trover\");}";
echo "  , function() {\$(this).removeClass(\"trover\");}";
echo ");";
echo "</script>";
$ui->footer();